home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / IRBIT2.DEM < prev    next >
Text File  |  1991-04-29  |  1KB  |  44 lines

  1. PROGRAM d7r11(input,output);
  2. (* driver for routine IRBIT2 *)
  3. (* calculate distribution of runs of zeros *)
  4. CONST
  5.    nbin=15;
  6.    ntries=500;
  7. VAR
  8.    i,iflg,ipts,iseed,j,n : integer;
  9.    delay : ARRAY [1..nbin] OF real;
  10.  
  11. FUNCTION twoton(n : integer) : integer;
  12. BEGIN
  13.    IF (n=0) THEN twoton := 1
  14.    ELSE twoton := 2*twoton(n-1)
  15. END;
  16.  
  17. (*$I MODFILE.PAS *)
  18. (*$I IRBIT2.PAS *)
  19.  
  20. BEGIN
  21.    iseed := 111;
  22.    FOR i := 1 to nbin DO BEGIN
  23.       delay[i] := 0.0
  24.    END;
  25.    ipts := 0;
  26.    FOR i := 1 to ntries DO BEGIN
  27.       IF (irbit2(iseed) = 1) THEN BEGIN
  28.          ipts := ipts+1;
  29.          iflg := 0;
  30.          FOR j := 1 to nbin DO BEGIN
  31.             IF ((irbit2(iseed) = 1) AND (iflg = 0)) THEN BEGIN
  32.                iflg := 1;
  33.                delay[j] := delay[j]+1.0
  34.             END
  35.          END
  36.       END
  37.    END;
  38.    writeln ('distribution of runs of n zeros');
  39.    writeln ('n':6,'probability':22,'expected':18);
  40.    FOR n := 1 to nbin DO BEGIN
  41.       writeln ((n-1):6,delay[n]/ipts:19:4,1/twoton(n):20:4);
  42.    END
  43. END.
  44.